Run me to get all the files in a specified directory on a Unix host (works best after using the Drag and Drop FTP sample).
Atul Butte
atul_butte@brown.edu
*)
global LF, CR, CRLF
property ftp_set : false
property ftp_host : ""
property ftp_user : ""
property ftp_directory : ""
property ftp_localname : ""
property ftp_transfer_type : ""
on run
set dialog_response to (display dialog "Enter the name of the machine where you want to get files" default answer ftp_host)
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_host to text returned of dialog_response
end if
set dialog_response to (display dialog "Enter your user–id on " & ftp_host default answer ftp_user)
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_user to text returned of dialog_response
end if
set dialog_response to (display dialog "Enter the directory of files to get on " & ftp_host & " to get" default answer ftp_directory)
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_directory to text returned of dialog_response
end if
set dialog_response to (display dialog "Do you want these downloaded as (1) MacBinary files, (2) text files, or (3) raw data files?" default answer "1")
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_transfer_type to ((text returned of dialog_response) as integer)
end if
set ftp_localname to (choose folder "Select destination for files") as string
set LF to (ASCII character of 10)
set CR to (ASCII character of 13)
set CRLF to CR & LF
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set localAddr to (tcp my address)
set localAddrList to text items of localAddr
set AppleScript's text item delimiters to {","}
set localAddrCommaString to localAddrList as string
set AppleScript's text item delimiters to oldDelimiters
set dialog_response to (display dialog "Enter the password for " & ftp_user & "@" & ftp_host & return & "Note: what you type is visible!" default answer "")
if (button returned of dialog_response ≠ "OK") then
return
else
set ftp_password to text returned of dialog_response
end if
set sss to (tcp connect to host ftp_host port 21)
try
readresponse(sss)
if (ftp_user ≠ "") then
tcp write stream sss data "USER " & ftp_user & return using ISO88591
readresponse(sss)
end if
if (ftp_password ≠ "") then
tcp write stream sss data "PASS " & ftp_password & return using ISO88591
readresponse(sss)
end if
if (ftp_directory ≠ "") then
tcp write stream sss data "CWD " & ftp_directory & return using ISO88591
readresponse(sss)
end if
set nlst_stream to (tcp wait for connect)
set nlst_stream_status to (tcp status stream nlst_stream)
set nlstHiByte to round (local port of nlst_stream_status) / 256 rounding down
set nlstLoByte to (local port of nlst_stream_status) mod 256